﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.IO;
using log4net;
using System.Reflection;
using MiserBlogData.Entities;
using MiserBlogMVC.Models;

namespace MiserBlogMVC
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

            routes.MapRoute(
                "Index",
                "{page}",
                new { controller = "Home", action = "Index", page = "" }
                , new { page = @"[0-9]*" }
            );

            //文章
            routes.MapRoute(
               "Article",
               "Article/{id}/{page}",
               new { controller = "Article", action = "Index", page = "" },
               new { id = @"[0-9]*", page = @"[0-9]*" }
           );

            routes.MapRoute(
                "IndexSort",
                "{action}/{id}/{page}",
                new { controller = "Home", page = UrlParameter.Optional },
                new { action = @"Tag|Categories", id = @"[0-9]*" }
            );


            routes.MapRoute(
                "Create",
                "{controller}/{action}/{id}",
                new { id = UrlParameter.Optional }, new { action = @"Create|Edit", id = @"[0-9]*" }
            );

            routes.MapRoute(
                "Manage",
                "{controller}/{action}/{page}",
                new { action = "Index", page = string.Empty }, new { page = @"[0-9]*" }
            );

           

        }
        protected void Application_Start()
        {

            log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));

            RegisterRoutes(RouteTable.Routes);

            ModelBinders.Binders.Add(typeof(UserVIP), new UserModelBinder());

            AreaRegistration.RegisterAllAreas();

            //AreaRegistration.RegisterAllAreas();

            //RegisterRoutes(RouteTable.Routes);

        }

    }
}